package com.example.webviewtest;

import static com.miui.enterprise.sdk.RestrictionsManager.BLUETOOTH_STATE;
import static com.miui.enterprise.sdk.RestrictionsManager.DISALLOW_CAMERA;
import static com.miui.enterprise.sdk.RestrictionsManager.DISALLOW_KEY_BACK;
import static com.miui.enterprise.sdk.RestrictionsManager.DISALLOW_KEY_HOME;
import static com.miui.enterprise.sdk.RestrictionsManager.DISALLOW_KEY_MENU;
import static com.miui.enterprise.sdk.RestrictionsManager.DISALLOW_STATUS_BAR;
import static com.miui.enterprise.sdk.RestrictionsManager.DISALLOW_TETHER;
import static com.miui.enterprise.sdk.RestrictionsManager.DISALLOW_TIMESET;
import static com.miui.enterprise.sdk.RestrictionsManager.DISALLOW_VPN;
import static com.miui.enterprise.sdk.RestrictionsManager.GPS_STATE;
import static com.miui.enterprise.sdk.RestrictionsManager.NFC_STATE;
import static com.miui.enterprise.sdk.RestrictionsManager.WIFI_STATE;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Application;
import android.bluetooth.BluetoothClass;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.webviewtest.databinding.ActivityMainBinding;
import com.example.webviewtest.databinding.ActivityTestA18Binding;
import com.miui.enterprise.sdk.ApplicationManager;
import com.miui.enterprise.sdk.DeviceManager;
import com.miui.enterprise.sdk.PhoneManager;
import com.miui.enterprise.sdk.RestrictionsManager;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

import yft.mdm.YftMdmManager;

public class TestA18Activity extends AppCompatActivity implements View.OnClickListener {
    private ActivityTestA18Binding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityTestA18Binding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.button1.setOnClickListener(this);
        binding.button2.setOnClickListener(this);
        binding.button3.setOnClickListener(this);
        binding.button4.setOnClickListener(this);
        binding.button5.setOnClickListener(this);
        binding.button6.setOnClickListener(this);
        binding.button7.setOnClickListener(this);
        binding.button8.setOnClickListener(this);
        binding.button9.setOnClickListener(this);
        binding.button10.setOnClickListener(this);
        binding.button11.setOnClickListener(this);
        binding.button12.setOnClickListener(this);
        binding.button13.setOnClickListener(this);
        binding.button14.setOnClickListener(this);
        binding.button15.setOnClickListener(this);
        binding.button16.setOnClickListener(this);
        binding.button17.setOnClickListener(this);
        binding.button18.setOnClickListener(this);
        binding.button19.setOnClickListener(this);
        binding.button20.setOnClickListener(this);
        binding.button21.setOnClickListener(this);
        binding.button22.setOnClickListener(this);
        binding.button23.setOnClickListener(this);
        binding.button24.setOnClickListener(this);
        binding.button25.setOnClickListener(this);
        binding.button26.setOnClickListener(this);
        binding.button27.setOnClickListener(this);
        binding.button30.setOnClickListener(this);
        binding.button31.setOnClickListener(this);
        binding.button32.setOnClickListener(this);
        binding.button33.setOnClickListener(this);
        binding.button34.setOnClickListener(this);
        binding.button35.setOnClickListener(this);
        binding.button36.setOnClickListener(this);
        binding.button37.setOnClickListener(this);
        binding.button38.setOnClickListener(this);
        binding.button39.setOnClickListener(this);
        binding.button40.setOnClickListener(this);
        binding.button41.setOnClickListener(this);
        binding.button42.setOnClickListener(this);
        binding.button43.setOnClickListener(this);
        binding.button45.setOnClickListener(this);
        binding.button47.setOnClickListener(this);
        binding.button48.setOnClickListener(this);
        binding.button49.setOnClickListener(this);
        binding.button50.setOnClickListener(this);
        binding.button51.setOnClickListener(this);
        binding.button52.setOnClickListener(this);
        binding.button53.setOnClickListener(this);
        binding.button54.setOnClickListener(this);
        binding.button55.setOnClickListener(this);
        binding.button56.setOnClickListener(this);

        binding.button28.setOnClickListener(this);
        binding.button57.setOnClickListener(this);
        binding.button581.setOnClickListener(this);
        binding.button59.setOnClickListener(this);
        binding.button591.setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.button1://允许使用设置中的选项
                List<String> hideMenu1 = new ArrayList<>();
                DeviceManager.getInstance().setSettingsMenuListToHide(hideMenu1);
                break;
            case R.id.button2://允许修改日期
                RestrictionsManager.getInstance().setRestriction(DISALLOW_TIMESET,false);
                break;
            case R.id.button3://允许使用wifi
                RestrictionsManager.getInstance().setControlStatus(WIFI_STATE,1);
                break;
            case R.id.button4:YftMdmManager.getInstance().setWifiScanPolicies(1);break;
            case R.id.button5://允许使用蓝牙
                RestrictionsManager.getInstance().setControlStatus(BLUETOOTH_STATE,4);
                break;
            case R.id.button6://允许使用GPS
                RestrictionsManager.getInstance().setControlStatus(GPS_STATE,1);
                break;
            case R.id.button7://允许使用热点
                RestrictionsManager.getInstance().setRestriction(DISALLOW_TETHER,false);
                break;
            case R.id.button8://允许使用NFC
                RestrictionsManager.getInstance().setControlStatus(NFC_STATE,1);
                break;
            case R.id.button9:YftMdmManager.getInstance().setOTGPolicies(1);break;
            case R.id.button10://允许使用VPN
                RestrictionsManager.getInstance().setRestriction(DISALLOW_VPN,false);
                break;
            case R.id.button11://允许使用卡槽数据
                PhoneManager.getInstance().controlCellular(1);
                break;
            case R.id.button12://允许使用卡槽
                PhoneManager.getInstance().setIccCardActivate(1,true);
//                PhoneManager.getInstance().setIccCardActivate(2,true);
                break;
            case R.id.button13:YftMdmManager.getInstance().setAppUninstallationPolicies(1, null);break;
            case R.id.button14:YftMdmManager.getInstance().setInstallForCallPolicies(2, new String[]{"com.ai.bss.app"});break;
            case R.id.button15:YftMdmManager.getInstance().uninstallPackage("com.ai.bss.app");break;
            case R.id.button16:YftMdmManager.getInstance().setAdbPolicies(1);break;
            case R.id.button17:YftMdmManager.getInstance().lockScreen();break;
            case R.id.button18://允许下拉状态栏
                RestrictionsManager.getInstance().setRestriction(DISALLOW_STATUS_BAR,false);
                break;
            case R.id.button19://允许任务键
                RestrictionsManager.getInstance().setFullScreenGesturesRestriction(false,0);//强制切换为导航按键模式
                RestrictionsManager.getInstance().setRestriction(DISALLOW_KEY_MENU,false);
                break;
            case R.id.button20://允许返回键
                RestrictionsManager.getInstance().setFullScreenGesturesRestriction(false,0);//强制切换为导航按键模式
                RestrictionsManager.getInstance().setRestriction(DISALLOW_KEY_BACK,false);
                break;
            case R.id.button21://允许home键
                RestrictionsManager.getInstance().setFullScreenGesturesRestriction(false,0);//强制切换为导航按键模式
                RestrictionsManager.getInstance().setRestriction(DISALLOW_KEY_HOME,false);
                break;
            case R.id.button22:YftMdmManager.getInstance().setFactoryResetPolicies(1);break;
            case R.id.button23://允许usb传输数据
                DeviceManager.getInstance().setUsbChargingOnlyEnable(false);
                break;
            case R.id.button24:YftMdmManager.getInstance().setDialCall(1);break;
            case R.id.button25:YftMdmManager.getInstance().setAnswerCallPolicies(1);break;
            case R.id.button26:YftMdmManager.getInstance().setMessagePolicies(1);break;
            case R.id.button27://允许使用相机
                RestrictionsManager.getInstance().setRestriction(DISALLOW_CAMERA,false);
                List<String>  storeNames= new ArrayList<>();
                storeNames.add("com.android.fileexplorer");
                storeNames.add("com.ai.bss.app");
                ApplicationManager.getInstance().addTrustedAppStore(storeNames);
                ApplicationManager.getInstance().enableTrustedAppStore(false);
                List<String> trustedAppStore = ApplicationManager.getInstance().getTrustedAppStore();
                System.out.println(1);
                break;
            case R.id.button30://隐藏设置菜单中的选项
                List<String> hideMenu = new ArrayList<>();
                Class<?> settngsMenuClass = DeviceManager.SettngsMenu.class;
                Field[] declaredFields = settngsMenuClass.getDeclaredFields();
                for (int i = 0; i < declaredFields.length; i++) {
                    if (Modifier.isStatic(declaredFields[i].getModifiers())) {
                        declaredFields[i].setAccessible(true);
                        try {
                            Object o = declaredFields[i].get(null);
                            hideMenu.add(o.toString());
                        } catch (IllegalAccessException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
                DeviceManager.getInstance().setSettingsMenuListToHide(hideMenu);
                break;
            case R.id.button31://禁止修改日期
                RestrictionsManager.getInstance().setRestriction(DISALLOW_TIMESET,true);
                ;break;
            case R.id.button32://禁止使用wifi
                RestrictionsManager.getInstance().setControlStatus(WIFI_STATE,0);
                break;
            case R.id.button33:YftMdmManager.getInstance().setWifiScanPolicies(0);break;
            case R.id.button34://禁止使用蓝牙
                RestrictionsManager.getInstance().setControlStatus(BLUETOOTH_STATE,0);
                break;
            case R.id.button35://禁止使用GPS
                RestrictionsManager.getInstance().setControlStatus(GPS_STATE,0);
                break;
            case R.id.button36://禁止使用热点
                RestrictionsManager.getInstance().setRestriction(DISALLOW_TETHER,true);
                break;
            case R.id.button37://禁止使用NFC
                RestrictionsManager.getInstance().setControlStatus(NFC_STATE,0);
                break;
            case R.id.button38:YftMdmManager.getInstance().setOTGPolicies(0);break;
            case R.id.button39://禁止使用VPN
                RestrictionsManager.getInstance().setRestriction(DISALLOW_VPN,true);
                break;
            case R.id.button40://禁止使用卡槽数据
                PhoneManager.getInstance().controlCellular(0);
                break;
            case R.id.button41://禁止使用卡槽
                PhoneManager.getInstance().setIccCardActivate(1,false);
//                PhoneManager.getInstance().setIccCardActivate(2,false);
                break;
            case R.id.button42:YftMdmManager.getInstance().setAppUninstallationPolicies(0, null);break;
            case R.id.button43://禁止安装软件，只允许安装白名单内的软件
                List<String> whiteList = new ArrayList<>();
                whiteList.add("com.ai.bss.app");
                ApplicationManager.getInstance().setApplicationWhiteList(whiteList);
                break;
            case R.id.button45:YftMdmManager.getInstance().setAdbPolicies(0);break;
            case R.id.button47://禁止下拉状态栏
                RestrictionsManager.getInstance().setRestriction(DISALLOW_STATUS_BAR,true);
                break;
            case R.id.button48://禁止任务键
                RestrictionsManager.getInstance().setFullScreenGesturesRestriction(true,0);//强制切换为导航按键模式
                RestrictionsManager.getInstance().setRestriction(DISALLOW_KEY_MENU,true);
                break;
            case R.id.button49://禁止使用返回键
                RestrictionsManager.getInstance().setFullScreenGesturesRestriction(true,0);//强制切换为导航按键模式
                RestrictionsManager.getInstance().setRestriction(DISALLOW_KEY_BACK,true);
                break;
            case R.id.button50://禁止home键
                RestrictionsManager.getInstance().setFullScreenGesturesRestriction(true,0);//强制切换为导航按键模式
                RestrictionsManager.getInstance().setRestriction(DISALLOW_KEY_HOME,true);
                break;
            case R.id.button51:YftMdmManager.getInstance().setFactoryResetPolicies(0);break;
            case R.id.button52://禁止使用usb传输数据
                DeviceManager.getInstance().setUsbChargingOnlyEnable(true);//设置usb仅充电模式
                break;
            case R.id.button53:YftMdmManager.getInstance().setDialCall(0);break;
            case R.id.button54:YftMdmManager.getInstance().setAnswerCallPolicies(0);break;
            case R.id.button55://禁止使用照相机
                RestrictionsManager.getInstance().setRestriction(DISALLOW_CAMERA,true);
                break;
            case R.id.button56:YftMdmManager.getInstance().setCameraPolicies(0);break;
            case R.id.button28:
                String imei1 = PhoneManager.getInstance().getIMEI(0);
                String imei2 = PhoneManager.getInstance().getIMEI(1);
                Toast.makeText(this, imei1+","+imei2, Toast.LENGTH_SHORT).show();
                break;
            case R.id.button57:
                ApplicationManager.getInstance().setApplicationSettings("com.example.webviewtest", ApplicationManager.FLAG_KEEP_ALIVE|ApplicationManager.FLAG_GRANT_ALL_RUNTIME_PERMISSION);
                break;
            case R.id.button581://黑名单P60
                List<String> blackList = new ArrayList<>();
                blackList.add("P60");
                List<String> wifiwhiteList = new ArrayList<>();
                DeviceManager.getInstance().setWifiApSsidWhiteList(wifiwhiteList);
                DeviceManager.getInstance().setWifiApSsidBlackList(blackList);
                break;
            case R.id.button59://白名单P60
                List<String> wifiblackList = new ArrayList<>();
                List<String> wifiwhiteList1 = new ArrayList<>();
                wifiwhiteList1.add("P60");
                DeviceManager.getInstance().setWifiApSsidBlackList(wifiblackList);
                DeviceManager.getInstance().setWifiApSsidWhiteList(wifiwhiteList1);
                break;
            case R.id.button591:
                List<String> wifiblackList1 = new ArrayList<>();
                List<String> wifiwhiteList11 = new ArrayList<>();
                DeviceManager.getInstance().setWifiApSsidBlackList(wifiblackList1);
                DeviceManager.getInstance().setWifiApSsidWhiteList(wifiwhiteList11);
                break;

        }
    }
}